home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Atari Mega Archive 1
/
Atari Mega Archive - Volume 1.iso
/
telecomm
/
wterm.arc
/
WTERM.C
< prev
next >
Wrap
C/C++ Source or Header
|
1985-11-20
|
16KB
|
485 lines
/*
* WTERM - A terminal program within a window
* "Stripped" Version
* by Matt Kimmel, 1987
*
* This is this stripped version of Window Term, a terminal program
* inside a window. The stripped version is considerably smaller
* and slightly faster than the Full version. However, it doesn't have
* any of the extra functions that the Full version has. In the Stripped
* version, you must use a seperate program to set the RS232 parameters.
*
* This code should be fairly portable. I have used calloc() instead
* of Malloc() because it initializes the reserved space to zeroes.
* This is a standard K&R function, so it should be implemented in
* all the ST compilers.
*
* The font size may be toggled between the normal font and "Icon"
* size with ALT-F. If you press ALT-S, a CTRL-S is sent, and the
* program won't accept any characters until you press ALT-S again,
* at which time a CTRL-Q is sent and output is resumed.
*/
#include <stdio.h>
#include <gemdefs.h>
#include <osbind.h>
/* defines for window gadgets */
#define NAME 0x0001
#define CLOSE 0x0002
#define FULL 0x0004
#define MOVE 0x0008
#define SIZE 0x0020
/* Macros to turn the mouse on and off */
#define MOUSE_ON graf_mouse(257,&j)
#define MOUSE_OFF graf_mouse(256,&j);
/* The size to set the RS232 buffer to */
#define BUFFER_SIZE 8192
/* Structure returned by Iorec() */
typedef struct {
char *ibuf;
int ibufsiz;
int ibufhd;
int ibuftl;
int ibuflow;
int ibufhi;
} IORECORD;
/* Standard VDI variables */
int contrl[12], intin[128],ptsin[128],intout[128],ptsout[128];
int w_handle, handle, workin[11], workout[57];
int x,y,w,h; /* Position of window */
int j; /* General-purpose junk variable */
int nx, ny; /* X,Y coordinates of next character to be output */
int tx, ty, tw, th; /* Size of the work area of the window */
int hsize, vsize; /* Horizontal and vertical size of characters */
int apid, menuid; /* Application and Menu IDs */
char rs232buf[BUFFER_SIZE]; /* RS232 Buffer */
main()
{
int j; /* Junk variable */
int msg[8]; /* Message buffer for evnt_mesag */
apid = appl_init(); /* Initialize our application */
menuid = menu_register(apid," Window Term"); /* Register in Desk menu */
handle = graf_handle(&j,&j,&j,&j); /* Get handle of the screen */
for(j=0;j++<=9;workin[j]=1); /* Set up workin array */
workin[10] = 2;
v_opnvwk(workin,&handle,workout); /* Open virtual workstation */
vst_alignment(handle,0,5,&j,&j); /* Set text alignment so that
so that the y coordinate is
the top line of a character
with v_gtext */
hsize = 8; /* Set horizontal and vertical sizes of characters */
vsize = ((Getrez() == 2)?(16):(8));
x=50; /* The window starts with these coordinates */
y=50;
w=200;
h=100;
set_rsbuf(); /* Set up new RS232 buffer */
for (;;) { /* For loop to infinity.... */
evnt_mesag(msg); /* Wait for a message */
if (msg[0] == AC_OPEN) /* Did someone open our accessory? */
acc(); /* Yes, go to the main part of the accessory */
}
}
/*
* This is the main loop in the program. It handles the window and
* input and output of characters.
*/
acc()
{
int msg[8], d, which; /* message buffer, junk variable, 'which' for
evnt_multi */
int i; /* Character accepted */
int a, j;
int desel = 0; /* Pseudo-Boolean variable determines whether our window
is the active window */
int dx,dy,dw,dh; /* Temporary variables */
int stopped = 0; /* Pseudo-Boolean; determines whether output has been
stopped with ALT-S */
long l;
if (init_window() == 0) return; /* If we can't create a window, forget it! */
align8(&x,&y,&w,&h); /* Make sure the text is on 8-bit boundaries */
graf_growbox(24,0,56,16,x,y,w,h); /* Growing box */
wind_open(w_handle,x,y,w,h); /* Open window */
wind_get(w_handle,WF_WORKXYWH,&tx,&ty,&tw,&th); /* Get work area */
nx=tx; /* Set next character's coordinates */
ny=ty;
clr(); /* Clear window */
Cauxout(17); /* Send a CTRL-Q, in case the user deselected the window
(sending a CTRL-S) and then ran a program or some such
which closed the window */
for(;;) {
which = evnt_multi(MU_MESAG|MU_TIMER,0,0,0,0,0,0,0,0,0,0,0,0,0,
msg,0,0,&d,&d,&d,&d,&d,&d);
wind_get(w_handle,WF_TOP,&a,&j,&j,&j); /* Make sure our window is
still on top */
if ((a != w_handle) && (desel == 0)) { /* Window has just
been deselected */
if (stopped != 1) Cauxout(19); /* Send a CTRL-S */
desel = 1;
}
else
if ((a == w_handle) && (desel == 1)) { /* Window has just been selected */
if (stopped != 1) Cauxout(17); /* Send a CTRL-Q */
desel = 0;
}
if ((which & MU_TIMER) && (a == w_handle)) { /* If there are no messages
and our window is on top */
if (Bconstat(2)) { /* Is there a character waiting at the keyboard? */
l = Bconin(2); /* Yes, get it */
if (l == 2031616L) /* Is it an ALT-S? */
if (stopped == 0) { /* Yes, is output stopped? */
Cauxout(19); /* No, stop output and send a CTRL-S */
stopped = 1;
}
else { /* Yes, start output and send a CTRL-Q */
Cauxout(17);
stopped = 0;
}
if (l == 2162688L) { /* Is the character an ALT-F? */
toggle_font(); /* Yes, toggle the font size and clear the window */
clr();
nx=tx;
ny=ty;
}
Cauxout((int)l); /* Output the character. If it's ALT-F, a 0 will
be output. */
}
if (Cauxis() && (stopped == 0)) { /* Is there a character waiting
at the modem port, and is output
enabled? */
i = Cauxin(); /* Yes. Get it and output it on the window. */
MOUSE_OFF;
outchar(i);
MOUSE_ON;
}
}
if (which & MU_MESAG) { /* Is there a message for us? */
switch(msg[0]) { /* Yes, evaluate it */
case WM_REDRAW : redraw(); /* Redraw the window */
nx=tx;
ny=ty;
break;
case WM_NEWTOP : /* Top the window that should be on top */
case WM_TOPPED : wind_set(w_handle,WF_TOP,w_handle,0,0,0);
clr();
break;
case AC_OPEN : form_alert(1,"[1][Window Terminal| |by Matt Kimmel|1987][Okay]");
break; /* Give some credits if someone clicks on our
menu item */
case AC_CLOSE : return; /* GEM has closed and deleted our window. */
break;
case WM_CLOSED : wind_close(w_handle);
graf_shrinkbox(24,0,56,16,x,y,w,h);
wind_delete(w_handle);
return; /* The user closed the window. Close it */
break; /* and delete it */
case WM_FULLED : full_window(); /* Full the window */
break;
case WM_MOVED : /* Move the window but make sure the next character
output appears after the last, and that the
window doesn't go off the screen */
wind_get(0,WF_WORKXYWH,&dx,&dy,&dw,&dh);
if (((msg[4] + msg[6]) - 1) > ((dx + dw) - 1))
msg[4] = ((dx + dw) - 1) - msg[6];
if (((msg[5] + msg[7]) - 1) > ((dy + dh) - 1))
msg[5] = ((dy + dh) - 1) - msg[7];